<template>
  <div>
    <router-view></router-view>
    <!-- <van-tabbar route active-color="darkred" v-model="isShow">
      <van-tabbar-item
        :name="item.id"
        :url="item.path"
        :icon="item.iconstyle"
        :class="item.id == $route.meta.id? 'changeColor' :'' "
        v-for="item in Tabbar"
        :key="item.id"
      >{{item.title}}</van-tabbar-item>
    </van-tabbar>-->
    <van-tabbar v-model="active" active-color="darkred" inactive-color="#000">
      <van-tabbar-item
        @click="handClick(item)"
        :icon="item.iconstyle"
        v-for="item in Tabbar"
        :key="item.id"
      >{{item.title}}</van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
import ToRoute from "@/components/home/ToRoute";
export default {
  data() {
    return {
      Tabbar: [
        { id: 0, path: "/home", title: "首页", iconstyle: "home-o" },
        { id: 1, path: "/special", title: "专题", iconstyle: "orders-o" },
        { id: 2, path: "/classify", title: "分类", iconstyle: "apps-o" },
        { id: 3, path: "/shopping", title: "购物车", iconstyle: "cart-o" },
        { id: 4, path: "/user", title: "我的", iconstyle: "friends-o" }
      ],
      active: 0
    };
  },
  components: {
    ToRoute
  },
  created() {
    console.log(this.$route.meta.id)
    this.active = this.$route.meta.id;
  },
  methods: {
    handClick(item) {
      if (item.id == 0) {
        this.$router.push(
          item.path,
          () => {},
          () => {}
        );
      } else if (item.id == 1) {
        this.$router.push(
          item.path,
          () => {},
          () => {}
        );
      } else if (item.id == 2) {
        this.$router.push(
          item.path,
          () => {},
          () => {}
        );
      } else if (item.id == 3) {
        const token = localStorage.getItem("token");
        if (!token) {
          this.$toast("请先登录");
          this.active = 4;
        }
        this.$router.push(
          item.path,
          () => {},
          () => {}
        );
      } else if (item.id == 4) {
        this.$router.push(
          item.path,
          () => {},
          () => {}
        );
      }
    }
  }
};
</script>

<style>
</style>